package com.md.controller;

import com.md.entity.Book;
import com.md.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/book")
@RestController
public class BookController {
    @Autowired
    public BookService service;
    @GetMapping
    public List<Book> selectAll() {
        return service.selectAll();
    }

    @GetMapping(params = "name")
    public List<Book> selectByName(String name) {
        return service.selectByName(name);
    }

    @GetMapping("{id}")
    public Book selectById(@PathVariable String id) {
        return service.selectById(Integer.parseInt(id));
    }

    @DeleteMapping("id")
    public int deleteById(@PathVariable String id) {
        return service.deleteById(Integer.parseInt(id));
    }
    @PostMapping
    public int insertStudent(@PathVariable Book book) {
        return service.insertStudent(book);
    }

    @PutMapping
    public int updateStudent(@PathVariable Book book) {
        return service.updateStudent(book);

    }
}
